<template>
	<view class="mainbgc">
		<view class="mainpadding">
			<view class="mainpadding_top ffffff radius">
				<view class="strongtext">上传个人简历附件</view>
				<view class="flexleft margin_top">
					<!-- 图片盒子 -->
					<view class="item_image_box flexcenter" v-if="files.length">
						<view class="item_image upbox radius flexcolumn">
							<view class="resume"></view>
							<view class="deletimg" @click="files=[]"></view>
						</view>
					</view>
					<!-- 上传图片 -->
					<view class="item_image_box flexcenter" @click="upfile()" v-if="!files.length">
						<view class="flexcolumn upimagebox radius">
							<view class="upimage">
								<image src="@/static/images/system/uploading.png" class="radius" mode=""></image>
							</view>
							<view style="margin-top: 20rpx;">上传文件</view>
						</view>
					</view>
				</view>
			</view>
			<view class="bottombtn margin_top" @click="submit">提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				files:[]
			}
		},
		onLoad() {
			this.getinfo()
		},
		methods: {
			getinfo(){
				httpRequest.request('/api/user/index', 'GET', {}, false, false, true).then(res => {
					if (res.code == 1) {
						this.files = res.data.grjl_text?res.data.grjl_text.split():[]
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			submit(){
				// if(this.files.length==0){
				// 	httpRequest.toast("请上传简历")
				// 	return false
				// }
				httpRequest.request('/api/user/editInfo', 'GET', {
					grjl:this.files.join()
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			upfile() {
				let _this = this
				wx.chooseMessageFile({
					count: 1,
					type: 'file',
					success(res) {
			
						for (let i = 0; i < res.tempFiles.length; i++) {
			
							_this.uploadImageService(res.tempFiles[i].path, _this.files)
						}
					}
				})
			},
			uploadImageService(url, upImg) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
			
					upImg.push(image_item);
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.upbox {
		width: 180rpx;
		height: 180rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
		background-color: RGBA(233, 244, 255, 1);
	}
	.item_image_box {
		width: 33.33%;
	}
	
	.item_image {
		position: relative;
		width: 180rpx;
		height: 180rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}

</style>
